package com;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import com.example.TukelaExampleDemo.R;
import com.example.navigation.GuideActivity;

public class SplashActivity extends Activity {
	boolean isFirstIn = false;

	private static final int GO_HOME = 1000;
	private static final int GO_GUIDE = 1001;
	//延迟三秒
	private static final long SPLASH_DELAY_MILLIS = 3000;
	private static final String SHAREDPREFERENCES_NAME = "first_pref";

	/**
	 * handler：跳转到不同界面
	 */
	private Handler mHandler = new Handler()
	{
		public void handleMessage(Message msg)
		{
			switch(msg.what)
			{
				case GO_HOME:
					goHome();
					break;
				case GO_GUIDE:
					goGuide();
					break;
			}
		}
	};

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash);

		init();
	}


	private void init() {
		// TODO Auto-generated method stub
		//读取SharedPreferences中需要的数据
		//使用SharedPreferences来记录程序的使用次数
		SharedPreferences preferences = getSharedPreferences(
				SHAREDPREFERENCES_NAME,MODE_PRIVATE);
		//取得相应的值，如果没有该值，说明还未写入，用true作为默认值
		isFirstIn = preferences.getBoolean("isFirstIn", true);

		isFirstIn=true;/*正式发布注释调该局*/

		//判断程序是第几次运行，如果是第一次运行则跳转到引导界面，否则跳转到主界面
		if(!isFirstIn)
		{
			mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS);
		}
		else
		{
			mHandler.sendEmptyMessageDelayed(GO_GUIDE, SPLASH_DELAY_MILLIS);
		}

	}


	private void goGuide() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(SplashActivity.this,GuideActivity.class);
		startActivity(intent);
		finish();
	}

	private void goHome() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(SplashActivity.this,MainActivity.class);
		startActivity(intent);
		finish();
	}

}
